<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="connect">连接</button>
    <button id="send" disabled="true">发送数据</button>
    <button id="content"></button>
    <script>
        let connect = document.querySelector('#connect')
        let send = document.querySelector('#send')
        let content = document.querySelector('#content')
        let ws = null
        connect.onclick = function () {
            ws = new WebSocket('ws://localhost:9998')
            ws.onopen = () => {
                console.log('连接服务器成功');
                send.disabled = false
            }
            ws.onmessage = msg => {
                console.log('从服务器接收到数据');
                content.innerHTML = msg.data
            }
            ws.onclose = e => {
                console.log('服务器关闭了连接');
                send.disabled = true
            }
        }
        send.onclick = function () {
            let object = {
                "action": "getData",
                "socketType": "trendData",
                "chartName": "trend",
                "value": ""
            }

            ws.send(JSON.stringify(object))
        }
    </script>
</body>
</html>